﻿#light

module PubSim.Table

open System
open Microsoft.FSharp.Control
open System.Configuration

// #r "System.Configuration.dll";; 

let maxNumTables = Convert.ToInt32(ConfigurationManager.AppSettings.Item("MaxNumberOfTables"))

/// Table:  (Note:  There will be multiple of these - see below).
type Table(initNumGlasses:int, initNumCups:int, initNumCustomers:int) =
    let mutable numGlasses = initNumGlasses
    let mutable numCups = initNumCups
    let mutable numCustomers = initNumCustomers
    let lockGlasses = new Object()
    let lockCups = new Object()
    let lockCustomers = new Object()
  
    member t.AddGlassToTable() =
         lock lockGlasses (fun() -> numGlasses <- numGlasses + 1)
         ignore()
    member t.AddCupToTable() =
         lock lockCups (fun() -> numCups <- numCups + 1)
         ignore()
    member t.AddCustomerToTable() =
         lock lockCustomers (fun() -> numCustomers <- numCustomers + 1)
         ignore()
    member t.FetchAllGlassesFromTable() =
         lock lockGlasses (fun() ->
             let numGlassesFetched = numGlasses
             numGlasses <- 0
             numGlassesFetched
         )
    member t.FetchAllCupsFromTable() =
        lock lockCups (fun() ->
            let numCupsFetched = numCups
            numCups <- 0
            numCupsFetched
        )
    member t.CustomerLeavesTable() =
        lock lockCustomers (fun() ->
            numCustomers <- numCustomers - 1
        )
        ignore()
    member t.NumGlassesOnTable() =
        numGlasses
    member t.NumCupsOnTable() =
        numCups
    member t.NumCustomersAtTable() =
        numCustomers
